package cn.net.vote.data.controller;

import cn.net.vote.data.domain.Page;
import cn.net.vote.data.domain.PageData;
import cn.net.vote.data.domain.ResponseBodyBean;
import cn.net.vote.data.service.IUserService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import java.io.IOException;
import java.util.List;

/**
 * 【描 述】：<数据导入管理模块控制层>
 * 【表 名】：<数据库表名称>
 * 【环 境】：J2SE 1.8

 * @version  version 1.0
 * @since    2018年9月11日
 */
@Api(description = "用户管理", value = "/")
@RestController
@EnableAutoConfiguration
@RequestMapping(value="/user")
public class UserController extends BaseController{

    @Autowired
    private IUserService userService;

    @ApiOperation(value = "查询所有商户", notes = "查询所有商户方法")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "page", dataType = "Page", required = true, value = "客户端传入JSON字符串", defaultValue = "")  })
    @ApiResponses({
            @ApiResponse(code=200,message="指示客服端的请求已经成功收到，解析，接受"),
            @ApiResponse(code=201,message="资源已被创建"),
            @ApiResponse(code=401,message="未授权"),
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=403,message="拒绝访问"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对"),
            @ApiResponse(code=406,message="不是指定的数据类型"),
            @ApiResponse(code=500,message="服务器内部错误")
    })
    @RequestMapping(value="/findAllUserlistPage", method= RequestMethod.POST)
    public  @ResponseBody ResponseBodyBean findAllUserlistPage(@RequestBody Page page ) throws IOException {
        int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
        ResponseBodyBean responseBodyBean = new ResponseBodyBean();
        PageData pdPageData = new PageData();
        List<PageData> findAllUser = userService.findAllUserlistPage(page);
        pdPageData.put("list", findAllUser);
        pdPageData.put("page", page);
        status = HttpStatus.OK.value();
        responseBodyBean.setResult(pdPageData);
        response.setStatus(status);
        return responseBodyBean;
    }

    @ApiOperation(value = "新增用户", notes = "新增用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "pd", dataType = "PageData", required = true, value = "客户端传入JSON字符串", defaultValue = "")  })
    @ApiResponses({
            @ApiResponse(code=200,message="指示客服端的请求已经成功收到，解析，接受"),
            @ApiResponse(code=201,message="资源已被创建"),
            @ApiResponse(code=401,message="未授权"),
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=403,message="拒绝访问"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对"),
            @ApiResponse(code=406,message="不是指定的数据类型"),
            @ApiResponse(code=500,message="服务器内部错误")
    })
    @RequestMapping(value="/addUser", method= RequestMethod.POST)
    public  @ResponseBody ResponseBodyBean addUser(@RequestBody PageData pd ) throws IOException {
        int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
        ResponseBodyBean responseBodyBean = new ResponseBodyBean();
        PageData pdPageData = new PageData();
        Integer result= userService.addUser(pd);
        pdPageData.put("result", result);
        pdPageData.put("pd", pd);
        status = HttpStatus.OK.value();
        responseBodyBean.setResult(pdPageData);
        response.setStatus(status);
        return responseBodyBean;
    }

    @ApiOperation(value = "修改用户", notes = "修改用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "pd", dataType = "PageData", required = true, value = "客户端传入JSON字符串", defaultValue = "")  })
    @ApiResponses({
            @ApiResponse(code=200,message="指示客服端的请求已经成功收到，解析，接受"),
            @ApiResponse(code=201,message="资源已被创建"),
            @ApiResponse(code=401,message="未授权"),
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=403,message="拒绝访问"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对"),
            @ApiResponse(code=406,message="不是指定的数据类型"),
            @ApiResponse(code=500,message="服务器内部错误")
    })
    @RequestMapping(value="/editUser", method= RequestMethod.POST)
    public  @ResponseBody ResponseBodyBean editUser(@RequestBody PageData pd ) throws IOException {
        int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
        ResponseBodyBean responseBodyBean = new ResponseBodyBean();
        PageData pdPageData = new PageData();
        Integer result= userService.editUser(pd);
        pdPageData.put("result", result);
        pdPageData.put("pd", pd);
        status = HttpStatus.OK.value();
        responseBodyBean.setResult(pdPageData);
        response.setStatus(status);
        return responseBodyBean;
    }

    @ApiOperation(value = "删除用户", notes = "删除用户")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "body", name = "pd", dataType = "PageData", required = true, value = "客户端传入JSON字符串", defaultValue = "")  })
    @ApiResponses({
            @ApiResponse(code=200,message="指示客服端的请求已经成功收到，解析，接受"),
            @ApiResponse(code=201,message="资源已被创建"),
            @ApiResponse(code=401,message="未授权"),
            @ApiResponse(code=400,message="请求参数没填好"),
            @ApiResponse(code=403,message="拒绝访问"),
            @ApiResponse(code=404,message="请求路径没有或页面跳转路径不对"),
            @ApiResponse(code=406,message="不是指定的数据类型"),
            @ApiResponse(code=500,message="服务器内部错误")
    })
    @RequestMapping(value="/delUser", method= RequestMethod.POST)
    public  @ResponseBody ResponseBodyBean delUser(@RequestBody PageData pd ) throws IOException {
        int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
        ResponseBodyBean responseBodyBean = new ResponseBodyBean();
        PageData pdPageData = new PageData();
        Integer result= userService.deleteUser(pd);
        pdPageData.put("result", result);
        pdPageData.put("pd", pd);
        status = HttpStatus.OK.value();
        responseBodyBean.setResult(pdPageData);
        response.setStatus(status);
        return responseBodyBean;
    }
}
